﻿namespace UnityEngine
{
    using System;
    using System.Runtime.CompilerServices;

    public sealed class MaterialPropertyBlock
    {
        private IntPtr m_Ptr;

        public MaterialPropertyBlock()
        {
            this.InitBlock();
        }

        public void AddColor(int nameID, Color value)
        {
            INTERNAL_CALL_AddColor(this, nameID, ref value);
        }

        public void AddColor(string name, Color value)
        {
            this.AddColor(Shader.PropertyToID(name), value);
        }

        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public extern void AddFloat(int nameID, float value);
        public void AddFloat(string name, float value)
        {
            this.AddFloat(Shader.PropertyToID(name), value);
        }

        public void AddMatrix(int nameID, Matrix4x4 value)
        {
            INTERNAL_CALL_AddMatrix(this, nameID, ref value);
        }

        public void AddMatrix(string name, Matrix4x4 value)
        {
            this.AddMatrix(Shader.PropertyToID(name), value);
        }

        public void AddVector(int nameID, Vector4 value)
        {
            INTERNAL_CALL_AddVector(this, nameID, ref value);
        }

        public void AddVector(string name, Vector4 value)
        {
            this.AddVector(Shader.PropertyToID(name), value);
        }

        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        public extern void Clear();
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        internal extern void DestroyBlock();
        ~MaterialPropertyBlock()
        {
            this.DestroyBlock();
        }

        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        internal extern void InitBlock();
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        private static extern void INTERNAL_CALL_AddColor(MaterialPropertyBlock self, int nameID, ref Color value);
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        private static extern void INTERNAL_CALL_AddMatrix(MaterialPropertyBlock self, int nameID, ref Matrix4x4 value);
        [MethodImpl(MethodImplOptions.InternalCall), WrapperlessIcall]
        private static extern void INTERNAL_CALL_AddVector(MaterialPropertyBlock self, int nameID, ref Vector4 value);
    }
}

